package com.wandian.ui.skins
{
	import flash.display.Graphics;

	import com.wandian.utils.ColorUtil;
	import com.wandian.utils.Const;



	public class TabSkin extends Skin
	{

		public function TabSkin()
		{
			super();
		}

		override public function updateDisplay(width:int, height:int, state:String, ... args):void
		{
			var borderColor:uint=getStyle("borderColor");
			var radius:int=getStyle("cornerRadius") ;
			var fillAlphas:Array=getStyle("fillAlphas");
			var fillColors:Array=getStyle("fillColors");
			var highlightAlphas:Array=getStyle("highlightAlphas");
			var themeColor:int=getStyle("themeColor");
			var borderDarkColor:int=ColorUtil.adjustBrightness(borderColor, -50);
			var themeDarkColor:int=ColorUtil.adjustBrightness(themeColor, -25);
			var g:Graphics=this.graphics
			g.clear();

			var w:int=width;
			var h:int=height;
			switch (state)
			{
				case "over":
				{
					var overFillColors:Array=[fillColors[2], fillColors[3]];
					var overFillAlphas:Array=[fillAlphas[2], fillAlphas[3]];

					//border
					Const.matrix.createGradientBox(w, h, Const.PI_2, 0, 0)
					g.beginGradientFill("linear", [themeColor, themeDarkColor], Const.fullAlpha, Const.fullRatio, Const.matrix)
					//g.drawRoundRect(0, 0, w, h, radius, radius)
					g.drawRoundRectComplex(0, 0, w, h, radius, radius, 0, 0)
					w-=2
					h-=2
					radius--
					g.drawRoundRectComplex(1, 1, w, h, radius, radius, 0, 0)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", overFillColors, overFillAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, radius, radius, 0, 0)
					g.endFill()
					// top highlight
					h/=2
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", [0xFFFFFF, 0xFFFFFF], highlightAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, radius, radius, 0, 0)
					break;
				}
				case "down":
				{
					var downFillColors:Array=[ColorUtil.adjustBrightness(themeColor, 85), ColorUtil.adjustBrightness(themeColor, 60)];

					//border
					Const.matrix.createGradientBox(w, h, Const.PI_2, 0, 0)
					g.beginGradientFill("linear", [themeColor, themeDarkColor], Const.fullAlpha, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(0, 0, w, h, radius, radius, 0, 0)
					w-=2
					h-=2
					radius--
					g.drawRoundRectComplex(1, 1, w, h, radius, radius, 0, 0)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", downFillColors, Const.fullAlpha, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, radius, radius, 0, 0)
					g.endFill()
					// top highlight
					h/=2
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", [0xFFFFFF, 0xFFFFFF], highlightAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, radius, radius, 0, 0)
					break;
				}
				case "disabled":
				{
					var disabledFillColors:Array=[fillColors[0], fillColors[1]];
					var disabledFillAlphas:Array=[fillAlphas[0] - 0.15, fillAlphas[1] - 0.15];

					//border
					Const.matrix.createGradientBox(w, h, Const.PI_2, 0, 0)
					g.beginGradientFill("linear", [borderColor, borderDarkColor], Const.halfAlpha, Const.fullRatio, Const.matrix)
					g.drawRoundRect(0, 0, w, h, radius, radius)
					w-=2
					h-=2
					radius--
					g.drawRoundRect(1, 1, w, h, radius, radius)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", disabledFillColors, disabledFillAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRect(1, 1, w, h, radius, radius)
					g.endFill()
					break;
				}
				default:
				{
					var upFillColors:Array=[fillColors[0], fillColors[1]];
					var upFillAlphas:Array=[fillAlphas[0], fillAlphas[1]];

					//border
					Const.matrix.createGradientBox(w, h, Const.PI_2, 0, 0)
					g.beginGradientFill("linear", [borderColor, borderDarkColor], Const.fullAlpha, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(0, 0, w, h, radius, radius, 0, 0)
					w-=2
					h-=2
					radius--
					g.drawRoundRectComplex(1, 1, w, h, radius, radius, 0, 0)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", upFillColors, upFillAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, radius, radius, 0, 0)
					g.endFill()
					// top highlight
					h/=2
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", [0xFFFFFF, 0xFFFFFF], highlightAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, radius, radius, 0, 0)
					break
				}
			}
		}
	}
}
